<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>厂家管理</title>
	<meta name="decorator" content="default"/>
	<link href="${ctxStatic}/jquery-select2/3.4/select2.min.css" rel="stylesheet" />
<script src="https://select2.github.io/vendor/js/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$(".js-example-basic-single").select2();
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		
		var factorId='';
		//设置厂家管理员
		function administrators(id){
			factorId=id;
			var href="${ctx}/jiujiu/jiuManufactor/memberList?factorId="+factorId+"&type=1";
			top.$.jBox.open('iframe:'+href,'选择用户',$(top.document).width()-800,$(top.document).height()-120,{
				buttons:{"关闭":true},
				loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
					$(".nav,.form-actions,[class=btn]", h.find("iframe").contents()).hide();
					$("body", h.find("iframe").contents()).css("margin","10px");
				}
			});
			
			//定时刷新
			 window.setInterval(function(){ 
				 if(factorId!=''){
						$.getJSON("${ctx}/jiujiu/jiuManufactor/getFactorAdmin",{factorId:factorId}, function(data){
		                    $('#guan'+factorId).html(data.name);
		                });
					}
			}, 1000);
			
			return false;
		}
		
		//绑定门店
		function bindingStore(factorId,index){
			var storeId=$('#store'+index).val();
			
			 $.getJSON("${ctx}/jiujiu/jiuManufactor/bindingStore",{factorId:factorId,storeId:storeId}, function(data){
                 alert(data.message);
                 if(data.msg=='success'){
                	 $('#f'+factorId).html(data.storeName);
                 }
                $('#stack'+index).css('display','none');
     			$('.modal-backdrop').remove();
            });
		}
		
		function seeStore(id){
			var href="${ctx}/jiujiu/jiuStore/?id="+id;
			top.$.jBox.open('iframe:'+href,'门店信息',$(top.document).width()-800,$(top.document).height()-120,{
				buttons:{"关闭":true},
				loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
					$(".nav,.form-actions,[class=btn]", h.find("iframe").contents()).hide();
					$("body", h.find("iframe").contents()).css("margin","10px");
				}
			});
		}
		
		function jiebangStore(id){		
			 top.$.jBox.confirm('确认解绑吗？','系统提示',function(v,h,f){
					if(v=='ok'){
						 $.getJSON("${ctx}/jiujiu/jiuManufactor/jiebangStore",{id:id}, function(data){
			                 alert(data.message);
			                 if(data.msg=='success'){
			                	 $('#f'+id).html("");
			                	 $('#f'+id).attr('onclick',"");
			                 }
			            });				
					}
			},{buttonsFocus:1});
			top.$('.jbox-body .jbox-icon').css('top','55px');
			return false;
			}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/jiujiu/jiuManufactor?factoClassId=${jiuManufactor.factoClassId}">厂家列表</a></li>
		<shiro:hasPermission name="jiujiu:jiuManufactor:edit"><li><a href="${ctx}/jiujiu/jiuManufactor/form?factoClassId=${jiuManufactor.factoClassId}">厂家添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="jiuManufactor" action="${ctx}/jiujiu/jiuManufactor/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<label>名称 ：</label><form:input path="name" htmlEscape="false" maxlength="50" class="input-medium"/>
		<label>所属分类 ：</label>
		<form:select path="factoClassId" class="js-example-basic-single">
			<form:option value="">全部</form:option>
			<c:forEach items="${jiuManufactorClassList}" var="jiuManufactorClass">
                   <form:option value="${jiuManufactorClass.id}">${jiuManufactorClass.name}</form:option>
			</c:forEach>
       	</form:select>
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
	</form:form>
	<tags:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered ">
		<thead><tr>
		<th>厂家名称</th>
		<th>厂家分类</th>
		<th>管理员</th>
		<th>封面图</th>
		<th>价格</th>
		<th>库存</th>
		<th>是否推荐</th>
		<th>排序</th>
		<th>绑定门店</th>
		<shiro:hasPermission name="jiujiu:jiuManufactor:edit"><th>操作</th></shiro:hasPermission></tr></thead>
		<tbody>
		<c:forEach items="${page.list}" var="manufactor" varStatus="vstatus">
		
		
			<!--绑定门店-->
			<div id="stack${vstatus.index}" class="modal hide fade"  data-focus-on="input:first">
	
			  <div class="modal-header">
			    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			    <h3>选择门店</h3>
			  </div>
			   <div class="modal-body">
						<div class="control-group">
							<div class="controls">
								<select id="store${vstatus.index}" class="js-example-basic-single">
									<c:forEach items="${JiuStoreList}" var="jiuStore">
						                   <option value="${jiuStore.id}">${jiuStore.name}</option>
									</c:forEach>
						       	</select>
							 </div>
						</div>
			  </div>
	  			<div class="modal-footer">
			    <button type="button" class="btn btn-primary" onclick="bindingStore(${manufactor.id},${vstatus.index})">Ok</button>
			  </div>
			</div>
			
			
			
			
			
			<tr>
				<td>${manufactor.name}</td>
				<td>${manufactor.className}</td>
				<td id="guan${manufactor.id}">${manufactor.memberName}</td>
				<td>
					<img src="${ctxUser }/jiu/${manufactor.logo}"   style="width:40px;height:40px"  />
				</td>
				<td>${manufactor.price}</td>
				<td>${manufactor.inventory}</td>
				<td>${manufactor.isRecommend eq '0'?'否':'是'}</td>
				<td>${manufactor.sort}</td>
				
				<td id="f${manufactor.id}" 
					<c:if test="${not empty manufactor.storeId}">
						onclick="seeStore(${manufactor.storeId})"
					</c:if>
				><b><a>${manufactor.storeName}</a></b></td>
				
				
				<shiro:hasPermission name="jiujiu:jiuManufactor:edit"><td>
					<div class="btn-toolbar" style="margin: 0;width: 400px;">
    				<a class="btn btn-success" href="${ctx}/jiujiu/jiuManufactor/form?id=${manufactor.id}&factoClassId=${manufactor.factoClassId}&cid=${jiuManufactor.factoClassId}">修改</a>
    				<a class="btn btn-success" href="${ctx}/jiujiu/jiuCarousel?type=1&manufactorId=${manufactor.id}">轮播管理</a>
					
					<div class="btn-group">
							<button class="btn btn-success">管理组 </button>
							<button class="btn btn-success dropdown-toggle" data-toggle="dropdown">
						    	<span class="caret"></span>
							</button>
							<ul class="dropdown-menu">
								<li><a href="javascript:administrators(${manufactor.id})">管理员设置</a></li>
								<li><a href="${ctx}/jiujiu/jiuReceiver?manufactorId=${manufactor.id}">接单员</a></li>
								<li><a href="${ctx}/jiujiu/jiuTakeDelivery?manufactorId=${manufactor.id}">送货员</a></li>
								<li><a href="#stack${vstatus.index}"  data-toggle="modal">绑定门店</a></li>
								
							</ul>
						</div>
					<c:set var="isDel" value="${fn:indexOf(fns:getUser().roleIdList, '10') == -1}" scope="page"/>
					<c:if test="${isDel }"> <!-- 平台客服  无权删除 -->
						<a class="btn btn-danger" href="${ctx}/jiujiu/jiuManufactor/delete?id=${manufactor.id}&factoClassId=${jiuManufactor.factoClassId}" onclick="return confirmx('确认要删除该厂家吗？', this.href)">删除</a>
					</c:if>
					<c:if test="${not empty jiuManufactor.storeId}">
						<a class="btn btn-danger" href="javascript:jiebangStore(${manufactor.id})">解除绑定</a>
					</c:if>
				</td>
				</td>
				</shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>
